class TimeSpan {

    private timeMap = {};

    private timeStart: number = 0;

    public setup() {
        this.timeStart = cc.sys.now();
    }

    // 游戏运行了多长时间.
    public timeSpan(): number {
        return cc.sys.now() - this.timeStart;
    }

    // 某任务开妈时调用.
    public time(label: string) {
        this.timeMap[label] = cc.sys.now();
    }

    // 某任务结束时调用,并返回任务执行时间周期.
    public timeEnd(label: string): number {
        if (this.timeMap[label]) {
            return cc.sys.now() - this.timeMap[label];
        } else {
            return 0;
        }
    }
}

export const timer: TimeSpan = new TimeSpan();